#!/bin/bash

# 设置MySQL连接参数
MYSQL_USER="root"
MYSQL_PASSWORD="123456"
MYSQL_HOST="192.168.13.10"
MYSQL_DB="demodata"
PORT=3306

# 生成城市列表
CITIES=("济南市" "济南市" "青岛市" "济南市" "青岛市" "青岛市" "青岛市" "济南市" "济南市" "烟台市" "烟台市" "潍坊市" "潍坊市" "潍坊市" "淄博市" "临沂市" "威海市" "济宁市" "泰安市" "泰安市" "日照市" "日照市" "德州市" "菏泽市" "滨州市")

# 生成交易方式列表
PAY_METHODS=("微信" "微信" "微信" "支付宝" "支付宝" "云闪付")

# 生成消费类型列表
CONSUME_TYPES=("食品" "食品" "食品" "食品" "日用品类" "日用品类" "日用品类" "运动户外" "运动户外" "电子产品" "家居用品")

# 获取当前时间
CURRENT_TIME=$(date +"%Y-%m-%d %H:%M:%S")

# 随机生成省份和城市
PROVINCE="山东省"
CITY=${CITIES[$RANDOM % ${#CITIES[@]}]}

# 随机生成交易方式、消费类型和交易金额
PAY_METHOD=${PAY_METHODS[$RANDOM % ${#PAY_METHODS[@]}]}
CONSUME_TYPE=${CONSUME_TYPES[$RANDOM % ${#CONSUME_TYPES[@]}]}
sjbt=$(awk -v seed=$RANDOM 'BEGIN{srand(seed); printf("%.2f",rand()*20)}')
ptbt=$(awk -v seed=$RANDOM 'BEGIN{srand(seed); printf("%.2f",rand()*30)}')
AMOUNT=$(($RANDOM % 1000))

# 将数据插入到MySQL数据库中
docker exec  mysql mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -P$PORT -h$MYSQL_HOST -D$MYSQL_DB -e "INSERT INTO transactions (create_time, province, city, pay_method, consume_type, sjbt,ptbt,amount) VALUES ('$CURRENT_TIME', '$PROVINCE', '$CITY', '$PAY_METHOD', '$CONSUME_TYPE', '$sjbt', '$ptbt', $AMOUNT);" 
